PCA Index Interactive Visualization Examples

PCA Index Interactive Visualization Examples#

import plotly.express as px

import config
import load_fred
import pca_index

DATA_DIR = config.DATA_DIR

import warnings
warnings.filterwarnings('ignore')
df = load_fred.load_fred(data_dir=DATA_DIR)
dfn = pca_index.transform_series(df)
## Visualize Principal Component 1
pc1, loadings = pca_index.pca(dfn, module="scikitlearn")
pc1.plot(color="red")
<Axes: xlabel='DATE'>
../../_images/13c9d46e870f8231153103a4cac5cbb0cafdc800156d65bac070a54bd920fc9d.png
# Simple version
fig = px.line(pc1)
fig.show()
# Using slider and quick views
pca_index.pc1_line_plot(pc1)
## Visualize normalized and raw series
dfn.plot(subplots=True, figsize=(10, 10));
../../_images/7f396041d98540652907e2d3f6426bbbcca7371ece350646dc728e6cc3d3c66e.png
fig = px.line(dfn, facet_col="variable", facet_col_wrap=1)
fig.update_yaxes(matches=None)
fig.show()
pca_index.plot_unnormalized_series(df)
pca_index.plot_normalized_series(dfn)